package jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;

public class JDBCDemo9 {
    public static void main(String[] args) {
        //用户注册
        UserInfo userInfo = InputUtil.getInputObject(new UserInfo(),"欢迎注册");
        try ( Connection conn = DBUtil.getConnection();){
            Statement statement = conn.createStatement();
            String sql = "INSERT INTO userinfo(username,password,nickname,age) VALUES (?,?,?,?)";
            PreparedStatement ps = conn.prepareStatement(sql);
            ps.setString(1, userInfo.getUsername());
            ps.setString(2, userInfo.getPassword());
            ps.setString(3, userInfo.getNickname());
            ps.setInt(4, userInfo.getAge());
            int num = ps.executeUpdate();
            System.out.println(num>0?"添加成功":"添加失败");
        } catch (SQLException e) {
            e.printStackTrace();
        }

    }
}
